package com.share.session.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * http://localhost:8080/sunxj-session/servlet/sessionDemo1?name=sunxj
 */
public class SessionDemo1 extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		if(name!=null){
			name = new String(name.getBytes("iso-8859-1"),"UTF-8");
		}
		//得到一个HttpSession对象
		HttpSession session = request.getSession();
		session.setAttribute("name", name);
		response.getWriter().write(session.getId());
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
